#include<bits/stdc++.h>
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define mid ((l+r)>>1)
#define File(xxx) freopen(xxx".in","r",stdin),freopen(xxx".out","w",stdout)
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    void pc(const char *s){
    	while(*s)putch(*s),s++;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x),putch(' '),write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);p3=obuf;}
}
using namespace IO;
const int N=1e6+5,Inf=1e9;
int n,rt=1,tot=1;
struct node{
	int cnt0[20],cnt1[20];
	int sum,son[2];
}tree[N];
ll ans=0;
void dfs(int x){
	if(tree[x].son[0]==0&&tree[x].son[1]==0){
		tree[x].cnt0[0]++; 
	}else{
		for(int i=0;i<2;i++){
			if(tree[x].son[i]){
				dfs(tree[x].son[i]);
				for(int j=1;j<20;j++)
					tree[x].cnt0[j]+=tree[tree[x].son[i]].cnt0[j-1],
					tree[x].cnt1[j]+=tree[tree[x].son[i]].cnt1[j-1];
			}else{
				tree[x].cnt0[1]++;
			}
		}
	}
	while(tree[x].sum){
		int minn0=Inf;
		for(int i=0;i<20;i++)if(tree[x].cnt0[i])
			{minn0=i;break;}
		int minn1=Inf;
		for(int i=0;i<20;i++)if(tree[x].cnt1[i])
			{minn1=i;break;}
		if(minn0==Inf&&minn1==Inf){
			break;
		}
		if(minn0<=minn1+2){
			ans+=minn0;
			tree[x].cnt0[minn0]--;
			tree[x].cnt1[minn0]++;
		}else{
			ans+=minn1+2;
			tree[x].cnt1[minn1]--;
			if(minn1+1<20)tree[x].cnt1[minn1+1]+=2;
		}
		tree[x].sum--;
	}
}
signed main(){
	File("id");
	read(n);
	for(int i=1;i<=n;i++){
		int x=1;
		char ch=getch();
		while(!isdigit(ch))
			ch=getch();
		while(isdigit(ch)){
			if(!tree[x].son[ch-'0'])
				tree[x].son[ch-'0']=++tot;
			x=tree[x].son[ch-'0'];
			ch=getch();
		}
		tree[x].sum++;
	}
	dfs(1);
	write(ans);
	return flush(),0;
}

